<?php

/**
 * This is the model class for table "{{tag}}".
 *
 * The followings are the available columns in table '{{tag}}':
 * @property integer $zt_id
 * @property integer $zca_id
 * @property string $zt_title
 * @property integer $zt_nums
 * @property integer $zt_closed
 * @property integer $zt_commend
 * @property integer $zt_listorder
 * @property integer $inputtime
 * @property integer $updatetime
 */
class Tag extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Tag the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{tag}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zca_id, zt_nums, zt_closed, zt_commend, zt_listorder, inputtime, updatetime', 'numerical', 'integerOnly'=>true),
			array('zt_title', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zt_id, zca_id, zt_title, zt_nums, zt_closed, zt_commend, zt_listorder, inputtime, updatetime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zt_id' => 'Zt',
			'zca_id' => '分类ID',
			'zt_title' => '关键词',
			'zt_nums' => '搜索次数',
			'zt_closed' => '是否有效',
			'zt_commend' => '推荐',
			'zt_listorder' => '排序',
			'inputtime' => '创建时间',
			'updatetime' => '更新时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		
		if($this->zt_title=='请输入关键字'){
			$this->zt_title = '';
		}

		$criteria->compare('zt_id',$this->zt_id);
		$criteria->compare('zca_id',$this->zca_id);
		$criteria->compare('zt_title',$this->zt_title,true);
		$criteria->compare('zt_nums',$this->zt_nums);
		$criteria->compare('zt_closed',$this->zt_closed);
		$criteria->compare('zt_commend',$this->zt_commend);
		$criteria->compare('zt_listorder',$this->zt_listorder);
		$criteria->compare('inputtime',$this->inputtime);
		$criteria->compare('updatetime',$this->updatetime);

		$criteria->order = " zt_nums DESC ";
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	/**
	 * 是否有效
	 */
	public function getCloasedStatus($type=null){
		if($type==null){
			return array(
 					''=>'全部',
					'1'=>'是',
					'2'=>'否',
			);
		}else{
			$level = $this->getCloasedStatus();
			if(array_key_exists($type,$level))
				return $level[$type];
		}
	}
	
	/**
 	 * 推荐状态
	 */
	public function getCommendStatus($type=null){
		if($type==null){
			return array(
					''=>'全部',
					'1'=>'否',
					'2'=>'是',
			);
		}else{
			$level = $this->getCommendStatus();
			if(array_key_exists($type,$level))
				return $level[$type];
		}
	}
}